package com.whz.http.datetime;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import java.util.TimeZone;

/**
 * 定义jackson的timezone为GMT+8
 *
 * @author whz
 */
@Configuration
@ConditionalOnClass(Jackson2ObjectMapperBuilder.class)
@ConditionalOnProperty(name = "generic.timezone.default.enable", havingValue = "true", matchIfMissing = true)
public class GlobalTimeZoneConfiguration {
    @Bean
    public Jackson2ObjectMapperBuilderCustomizer globalCustomizer() {
        return builder -> builder.timeZone(TimeZone.getTimeZone("GMT+8"));
    }
}